package com.witdata.controller.course;

import java.util.List;

import org.springframework.web.bind.annotation.*;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.vo.CourseSubjectsVo;
import com.witdata.common.exception.GlobalException;
import com.witdata.common.service.course.CourseSubjectsService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/course/subjects")
@Tag(name = "课程题单管理")
public class CourseSubjectsController {

    private final CourseSubjectsService courseSubjectsService;
    
    @GetMapping("/list/subjects/{courseId}")
    public Result<List<CourseSubjectsVo>> getCourseSubjectsList(@PathVariable("courseId") Long courseId) {
        return Result.ok(Status.SUCCESS, courseSubjectsService.getCourseSubjectsList(courseId));
    }

    @PostMapping("/create/subjects")
    public Result<String> createCourseSubjects(@RequestBody CourseSubjectsVo courseSubjectsVo) {
        Boolean exists = courseSubjectsService.createCourseSubjects(courseSubjectsVo);
        if (!exists) throw new GlobalException(Status.COURSE_SUBJECTS_NOT_FOUND);
        return Result.ok(Status.SUCCESS);
    }

    @PutMapping("/update/subjects")
    public Result<String> updateCourseSubjects(@RequestBody CourseSubjectsVo courseSubjectsVo) {
        Boolean exists = courseSubjectsService.updateCourseSubjects(courseSubjectsVo);
        if (!exists) throw new GlobalException(Status.COURSE_SUBJECTS_NOT_FOUND);
        return Result.ok(Status.SUCCESS);
    }

    @DeleteMapping("/delete/subjects/{courseSubjectsId}")
    public Result<String> deleteCourseSubjects(@PathVariable("courseSubjectsId") Long courseSubjectsId) {
        Boolean exists = courseSubjectsService.deleteCourseSubjects(courseSubjectsId);
        if (!exists) throw new GlobalException(Status.COURSE_SUBJECTS_NOT_FOUND);
        return Result.ok(Status.SUCCESS);
    }

}
